//
//  DetailTransferTableViewCell.m
//  HQJFacilitator
//
//  Created by mymac on 2016/10/10.
//  Copyright © 2016年 Fujian first time iot technology investment co., LTD. All rights reserved.
//

#import "DetailTransferTableViewCell.h"
@interface DetailTransferTableViewCell()
@property (nonatomic,strong)UILabel *oneBonusLabel;
@property (nonatomic,strong)UILabel *oneTypeLabel;

@property (nonatomic,strong) UIImageView*arrowImageView;

@property (nonatomic,strong)UILabel *timerLabel;

@property (nonatomic,strong)UILabel *twoTypeLabel;

@property (nonatomic,strong)UILabel *twoBonusLabel;

@property (nonatomic,strong)UILabel *jiFenLabel;



@end
@implementation DetailTransferTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
    
//        [self update];
    
    
    }
    
    
    
    
    return self;
    
    
}


-(UILabel *)oneBonusLabel {
    if (!_oneBonusLabel) {
        _oneBonusLabel = [[UILabel alloc]init];
        _oneBonusLabel.font = [UIFont systemFontOfSize:18];
        _oneBonusLabel.textColor = [ManagerEngine getColor:@"f54949"];
        [self addSubview:_oneBonusLabel];
    }
    
    
    
    return _oneBonusLabel;
}
-(UILabel *)oneTypeLabel {
    if (!_oneTypeLabel) {
        _oneTypeLabel = [[UILabel alloc]init];
        _oneTypeLabel.textColor = [ManagerEngine getColor:@"999999"];
        _oneTypeLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_oneTypeLabel];
    }
    
    
    return _oneTypeLabel;
}

-(UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [[UIImageView alloc]init];
        _arrowImageView.image = [UIImage imageNamed:@"detailArrow"];
//        _arrowImageView
        _arrowImageView.contentMode = UIViewContentModeScaleAspectFit;
        

        [self addSubview:_arrowImageView];
    }
    
    
    
    
    return _arrowImageView;
}

-(UILabel *)timerLabel {
    if (!_timerLabel) {
        _timerLabel = [[UILabel alloc]init];
        _timerLabel.font = [UIFont systemFontOfSize:12];
        _timerLabel.textColor = [ManagerEngine getColor:@"999999"];
        [self addSubview:_timerLabel];
    }
    
    
    
    return _timerLabel;
}
-(UILabel *)twoBonusLabel {
    if (!_twoBonusLabel ) {
        _twoBonusLabel = [[UILabel alloc]init];
        _twoBonusLabel.font = [UIFont systemFontOfSize:18];
        _twoBonusLabel.textColor = [ManagerEngine getColor:@"00c2ae"];
        [self addSubview:_twoBonusLabel];
    }
    
    
    
    return _twoBonusLabel;
}

-(UILabel *)twoTypeLabel {
    
    if (!_twoTypeLabel) {
        
        _twoTypeLabel = [[UILabel alloc]init];
     _twoTypeLabel.textColor = [ManagerEngine getColor:@"999999"];
        _twoTypeLabel.font = [UIFont systemFontOfSize:12];

        [self addSubview:_twoTypeLabel];
    }
    
    
    
    return _twoTypeLabel;
}

-(UILabel *)jiFenLabel {
    
    if (!_jiFenLabel) {
        _jiFenLabel = [[UILabel alloc]init];
        _jiFenLabel.text = @"积分";
        _jiFenLabel.textColor = [ManagerEngine getColor:@"999999"];
        _jiFenLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:_jiFenLabel];
    }
    
    
    return _jiFenLabel;
}


-(void)update {
    self.arrowImageView.center = CGPointMake(self.center.x, self.center.y);
    self.arrowImageView.backgroundColor = [UIColor redColor];
    self.arrowImageView.bounds = CGRectMake(0, 0, 100, 20);
    
}



-(void)setCellModel:(DerailModel *)cellModel {
    
    _cellModel = cellModel;
    self.oneBonusLabel.text = [NSString stringWithFormat:@"%.2f",[cellModel.amount floatValue]];
    
    self.timerLabel.text = cellModel.tradetime;

    if ([cellModel.comment isEqualToString:@"服务商积分转个人账户"]) {
        self.oneTypeLabel.text = @"(服务商)";
        self.twoTypeLabel.text = @"(会员)";
        self.twoBonusLabel.text =[NSString stringWithFormat:@"%.2f",[cellModel.camount floatValue]];

    } else if ([cellModel.comment isEqualToString:@"服务商积分转名下其他会员账户"]) {
        self.oneTypeLabel.text = @"(服务商)";
        self.twoTypeLabel.text = [NSString stringWithFormat:@"(%@)",cellModel.trealname];
        self.twoBonusLabel.text =[NSString stringWithFormat:@"%.2f",[cellModel.camount floatValue]];

    } else {
        
        self.oneTypeLabel.text = @"(会员)";
        self.twoTypeLabel.text = @"(服务商)";
        self.twoBonusLabel.text = [NSString stringWithFormat:@"%.2f",[cellModel.amount floatValue]];

    }
    
}

-(void)updateLayout {
    
    [super updateLayout];
    CGFloat oneBonusSize = [ManagerEngine setTextWidthStr:self.oneBonusLabel.text andFont:[UIFont systemFontOfSize:18]];
    CGFloat timerSize = [ManagerEngine setTextWidthStr:self.timerLabel.text andFont:[UIFont systemFontOfSize:12]];
    CGFloat twoBonusSize = [ManagerEngine setTextWidthStr:self.twoBonusLabel.text andFont:[UIFont systemFontOfSize:18]];
    CGFloat oneTypeSize = [ManagerEngine setTextWidthStr:self.oneTypeLabel.text andFont:[UIFont systemFontOfSize:12]];
    CGFloat twoTypeSize = [ManagerEngine setTextWidthStr:self.twoTypeLabel.text andFont:[UIFont systemFontOfSize:12]];

    self.oneBonusLabel.sd_layout.leftSpaceToView(self,EDGE).topSpaceToView(self,EDGE).heightIs(20).widthIs(oneBonusSize);
    
    self.oneTypeLabel.sd_layout.leftEqualToView(self.oneBonusLabel).topSpaceToView(self.oneBonusLabel,0).heightIs(20).widthIs(oneTypeSize);
  
    self.timerLabel.sd_layout.leftSpaceToView(self,(WIDTH-timerSize)/2).topEqualToView(self.oneTypeLabel).heightIs(20).widthIs(timerSize);
    
    self.twoBonusLabel.sd_layout.leftSpaceToView(self,WIDTH-twoBonusSize-EDGE).topEqualToView(self.oneBonusLabel).heightIs(20).widthIs(twoBonusSize);
    
    self.twoTypeLabel.sd_layout.leftSpaceToView(self,WIDTH-twoTypeSize-EDGE).topSpaceToView(self.twoBonusLabel,0).heightIs(20).widthIs(twoTypeSize);
//    self.arrowImageView.center = CGPointMake(self.timerLabel.center.x, self.timerLabel.center.y-20);
//    self.arrowImageView.backgroundColor = [UIColor redColor];
    self.arrowImageView.sd_layout.leftEqualToView(self.timerLabel).topSpaceToView(self,EDGE+5).heightIs(10).widthIs(100);
//    self.arrowImageView.bounds = CGRectMake(0, 0, 100, 20);
//    self.jiFenLabel.backgroundColor = [UIColor greenColor];
    self.jiFenLabel.sd_layout.leftSpaceToView(self,(WIDTH/2-15)).topSpaceToView(self,EDGE-7).heightIs(12).widthIs(30);
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
